package org.example.mapper;

import org.example.dto.SubUserDto;
import org.example.dto.UserDto;
import org.example.po.SubUser;
import org.example.po.User;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;

import java.util.List;

/**
 * @author liyishan
 * @date 2023/6/6 16:58
 * @apiNote
 */
@Mapper
public interface User3Mapper {
    @Mappings({
            @Mapping(source = "pwd",target = "password"),
            @Mapping(source = "subUser", target = "subUserDto")
    })
    UserDto userToUserDto(User user);

    @Mappings({
            @Mapping(source = "pwd",target = "password"),
            @Mapping(source = "subUser", target = "subUserDto")
    })
    List<UserDto> userToUserDto(List<User> users);


    //只能存在一个default修饰的方法
    default SubUserDto subSource2subTarget(SubUser subUser) {
        if (subUser == null) {
            return null;
        }
        SubUserDto subUserDto = new SubUserDto();
        subUserDto.setResult(!subUser.getDeleted().equals(0));
        subUserDto.setName(subUser.getName()==null?"":subUser.getName());
        return subUserDto;
    }
}
